package com.tvsinfo.jdk.demo.case2_function_interface;

public class CusFunctionDemo1 {

    public static void main(String[] args) {
        Iron iron = new Iron();
        System.out.println("--------------------------");


        //匿名内部类
        CarFatory<Iron, CaseCar> carFatory =new CarFatory<Iron, CaseCar>() {
            @Override
            public CaseCar convert(Iron iron) {
                return new CaseCar(iron);
            }
        };

        CaseCar car =  carFatory.convert(iron);
        car.drive();

        System.out.println("--------------------------");

        //直接Lambda代替内部类
        CarFatory<Iron, CaseCar> carFatory2 = iron1 -> new CaseCar(iron1);
        CaseCar car2 = carFatory.convert(iron);
        car2.drive();
    }



    public static class Iron {
        public Iron() {
            System.out.println("get Iron");
        }
    }


    public static class CaseCar {
        public CaseCar(Iron iron) {
            System.out.println("get Iron build car");
        }

        public void drive() {
            System.out.println("I am Drive");
        }

    }

}
